/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package SessionBeans;

import EntityBeans.Product;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import javax.ejb.Stateless;
import javax.faces.model.ListDataModel;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author Pierre
 */
@Stateless
public class ProductFacade extends AbstractFacade<Product> implements ProductFacadeLocal {
    @PersistenceContext(unitName = "Apppstore-ejbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public ProductFacade() {
        super(Product.class);
    }
    
    @Override
    public List<Product> ProductByType(long type)
        {
            
            Query query;
            query = em.createNamedQuery("Product.findByType");
            query.setParameter("type",type);
            return query.getResultList();
             
        }
    
     @Override
    public Product ProductByID(int id)
        {
            System.out.println("ici ProductByID");
            Query queryp;
            queryp = em.createNamedQuery("Product.findById");
            queryp.setParameter("id",id);
            return (Product)queryp.getSingleResult(); 
        }
    
}
